<?php

/**
 * +---------------------------------------------------------------
 * | Author: 北京永青宇创科技有限公司
 * | Date: 2020/03/12
 * | 版本: 6.0
 * +---------------------------------------------------------------
 * | CopyRight: 北京永青宇创科技有限公司 All rights reserved.
 * +---------------------------------------------------------------
 * | 版权声明：云豹不是一个自由软件，是云豹官方推出的商业源码。
 * | 严禁在未经许可的情况下拷贝、复制、传播、使用云豹的任意代码
 * | 如有违反，请立即删除，否则您将面临承担相应，法律责任的风险。
 * | 如果需要取得官方授权，请联系官方 https://www.gepardshop.com
 * +---------------------------------------------------------------
 */

namespace app\mall\controller;

use app\common\controller\Ucenter;

use app\common\builder\ListBuilder;

class My extends Ucenter {
	protected $model;

	protected function initialize()
	{
		parent::initialize(); // TODO: Change the autogenerated stub

		$this->model = model('mall/mallOrder');

		$this->assign('meta_title', '积分商城');
	}

	public function index()
	{
		// 获取所有记录

		$map   = [
			'mo.uid'    => $this->auth->id,
			'mo.status' => 1,
		];
		$field = 'mo.*,mg.title as goods_title';
		list($list, $pagehtml) = $this->model->alias('mo')->join('mall_goods mg', 'mg.id=mo.goods_id')->where($map)->field($field)->order('mo.id desc')->pagedata(10);
		$list = listObject2array($list);

		$builder = new ListBuilder();

		return $builder->setMetaTitle('订单管理')
		               ->setSuggest('我的兑换订单列表')
			//            ->addTopButton('addnew',['href'=>url('edit')])
			//            ->addTopButton('forbid')
			//            ->addTopButton('recycle')
			           ->addSearchItem('title', 'text', '商品名称', '商品名称关键字')
		               ->addTableColumn('id', '订单id')
		               ->addTableColumn('goods_title', '商品名称')
		               ->addTableColumn('price', '消耗' . Modc('SCORE_TITLE', '', 'PAYCENTER'))
		               ->addTableColumn('buy_num', '购买数量')
		               ->addTableColumn('create_time', '兑换时间', 'time')
		               ->addTableColumn('status', '状态', 'toggle', ['model' => 'mall/mallOrder'])
		               ->addTableColumn('right_button', '操作', 'btn')
		               ->setTableDataList($list)
		               ->setTableDataPage($pagehtml)
		               ->addRightButton('self', ['title' => '浏览', 'href' => url('mall/index/detail', ['oid' => '__data_id__'])])
		               ->addRightButton('edit', ['href' => url('edit', ['id' => '__data_id__'])])
		               ->addRightButton('delete', ['model' => 'mall/mallOrder'])
		               ->setTemplate('layout/ucenter/list')
		               ->checkbox(false)
		               ->display();
	}

	public function MyUnpayed()
	{
		// 获取所有记录
		$map['uid']    = $this->auth->id;
		$map['status'] = 1;

		$list = model('mall/mallOrder')->select();
		$list = listObject2array($list);
		foreach($list as &$item) {
			$appinfo             = model('mall/mallGoods')->find($item['goods_id']);
			$item['goods_title'] = $appinfo['title'];
		}
		// 使用Builder快速建立列表页面
		$this->assign('meta_title', '我的积分订单');

		//使用builder快速建立页面
		$builder = new ListBuilder();

		//处理标题和按钮
		$builder->title('积分订单' . '管理')
		        ->buttonModalPopup(url('mallOrder/Edit'));

		//处理字段

		$builder->keyText('out_pay_sn', '支付单号');
		$builder->keyText('goods_title', '商品名称');

		$builder->keyText('price', '消耗积分');

		$builder->keyText('buy_num', '兑换数量');

		$builder->keyText('pay_status', '是否支付成功');

		$builder->keyText('create_time', '创建时间');

		//渲染数据处理分页
		$builder->keyDoActionModalPopup('MallOrder/Edit?id=###', '用户操作')
		        ->data($list)
		        ->setTemplate('listbuilder/ucenter');

		return $builder->display();

		return $this->fetch();
	}
}